
// test.iot.store
// const BASE_URL='https://ly.iot.store'

// 全局请求封装
export default (url, method, params) => {
	// 域名
	const userObj = JSON.parse(uni.getStorageSync('user'))
	const BASE_URL=uni.getStorageSync('urlText')
	// const BASE_URL="http://192.168.1.46:9999"
	// const BASE_URL='https://tmc.iot.store'
	// const BASE_URL='https://'+userObj.domain
	const paramsInfo={
		deptId: userObj.userDeptId,
		isDept:userObj.deptType===0?1:0,//判断是否是全部单位,
		authorization: userObj.accessToken,
		tenantId:userObj.id
	}
	uni.showLoading({
		title: "加载中"
	});
	// if(!token ){
	// 	// 执行没有登录的逻辑

	// 	return;
	// }
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + url,
			method: method,
			header: {
				// token: token,
				'authorization':'Bearer ' + paramsInfo.authorization,
				'tenant-id': paramsInfo.tenantId
			},
			data: {
				...{
					deptId: paramsInfo.deptId,
					isDept: paramsInfo.isDept
				},
				...params
			},
			success(res) {
				resolve(res.data);
			},
			fail(err) {
				reject(err)
			},
			complete() {
				uni.hideLoading();
			}
		})
	})
}